package com.flycms.module.project.service;

import com.flycms.core.entity.PageVo;
import com.flycms.module.project.dao.ProjectDao;
import com.flycms.module.project.model.Project;
import com.flycms.module.project.param.ProjectParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectService {

    @Autowired
    private ProjectDao projectDao;

    /**
     * 分页查询
     * @param param 查询参数
     * @return 返回分页参数
     */
    public PageVo<Project> page(ProjectParam param) {
        PageVo<Project> pageVo = new PageVo<>(param.getPageIndex());
        pageVo.setRows(param.getPageSize());
        int count = projectDao.count(param);
        if(count <= 0){
            return new PageVo<>(param.getPageIndex());
        }
        List<Project> projects =
                projectDao.selectByPage(param, pageVo.getOffset(), pageVo.getRows());
        pageVo.setList(projects);
        pageVo.setCount(count);
        return pageVo;
    }

    /**
     * 保存项目
     * @param project 项目
     */
    public void save(Project project) {
        projectDao.insertSelective(project);
    }

    /**
     * 删除
     * @param id id
     */
    public void del(Long id) {
        projectDao.del(id);
    }

    /**
     * 更新
     * @param project 项目信息
     */
    public void update(Project project) {
        projectDao.update(project);
    }
}
